<template>
  <!--促成交-->
  <el-dialog
    :close-on-click-modal="false"
    title="促成交"
    :beforeClose="handleClose"
    :visible.sync="dialogVisible"
    width="700px">
    <el-form :model="form" ref="form" size="small" :rules="rules" label-width="120px">
       <el-form-item label="建议开发时间">{{form.itemValue1}}</el-form-item>
       <el-form-item label="预计结束时间">{{form.itemValue2}}</el-form-item>
      <el-form-item label="对比价格" prop="dealComparePrice">
        <el-radio-group v-model="form.dealComparePrice">
          <el-radio :label="item.cddId" v-for="item in typeList1" :key="item.cddId">{{ item.cddValue }}</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="付款条件" prop="dealPayMethod">
        <el-checkbox-group v-model="form.dealPayMethod">
          <el-checkbox :label="item.cddId" v-for="item in typeList2" :key="item.cddId">{{item.cddValue}}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="handleConfirm" :loading="btnLoading">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import {getCustomerSetting,} from '@/api/partner'
import {customerNewCycleConfirm} from '@/api/company'
import {validatePhone} from '@/utils/validate';
import {formatDate} from '@/utils/date';
import store from '@/store'
import { mapGetters } from 'vuex'



const defaultForm = {
  cglId:'',
  dealComparePrice:'',
  dealPayMethod:[],
  itemValue1:'',
  itemValue2:'',
};
export default {
  name: "index",
  data(){
    return {
      dialogVisible:false,
      btnLoading:false,
      form:JSON.parse(JSON.stringify(defaultForm)),
      rules:{
        dealPayMethod:[{required: true, message: '此项必填', trigger: 'change'},],
        dealComparePrice:[{required: true, message: '此项必填', trigger: 'change'},]
      },

      typeList1:[],
      typeList2:[]

    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),
  },
  components : {

  },
  created() {

  },
  filters: {

  },
  methods:{

    //显示
    showPop(item){
      this.dialogVisible = true;
      this.form.cglId = item.cglId;
      this.form.dealComparePrice = '';
      this.form.dealPayMethod = [];
      let curItem = item.stepList.find((el)=>{
        return el.itemCode == 'deal'
      })
      this.form.itemValue1 = curItem.itemValue1;
      this.form.itemValue2 = curItem.itemValue2;
      this.getCustomerSettingList();
    },

    //获取客户配置
    getCustomerSettingList(){
      getCustomerSetting().then((res)=>{
        res.forEach((el)=>{
          if(el.cdtCode == 'compare_price_type') {
            this.typeList1 = el.data
          }else  if(el.cdtCode == 'pay_method_type') {
            this.typeList2 = el.data
          }
        });
      })
    },

    //关闭
    handleClose(){
      this.$refs.form.clearValidate();
      this.dialogVisible = false;
      this.btnLoading = false;
    },

    //提交
    handleConfirm(){
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.btnLoading = true;
          let data = JSON.parse(JSON.stringify(this.form));
          data.dealPayMethod = data.dealPayMethod.join(",")
          customerNewCycleConfirm(data).then((res)=>{
            this.btnLoading = false;
            this.handleClose();
            this.$emit('getSteps')
          }).catch(()=>{
            this.btnLoading = false;
          })
        }
      })
    },
  },
}
</script>

<style  lang="scss">

</style>
